package com.flong.utils;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import com.flong.entity.User;

/**
 * @Description	WebUtils
 * @ClassName	WebUtils
 * @Date		2018年2月23日 下午6:01:15
 * @Author		liangjl
 * @Copyright (c) All Rights Reserved, 2018.
 */
public class WebUtils {

	private final static Logger logger = LoggerFactory.getLogger(WebUtils.class);
	private final static String CURRENT_USER  = "CURRENT_USER";
	  
    /**
	 * @Description 获取session信息
	 * @Author		liangjl
	 * @Date		2018年2月23日 下午5:38:21
	 * @param request
	 * @return 参数
	 * @return User 返回类型 
	 * @throws
     */
	public static User getSessionCurrentUser(HttpServletRequest request) {
		return (User) request.getSession().getAttribute(CURRENT_USER);
	}
    
	
	/**
	 * 判断方法是否需要登录
	 * @param request
	 * @return
	 */
	public static boolean isLogin(HttpServletRequest request) {
		//从session获取
		User user = WebUtils.getSessionCurrentUser(request);
		if(ObjectUtil.isEmpty(user)) {
			logger.info("session为空");
			return false;
		}else {
			logger.info("session不为空");
			return true;
		}
	}
	
	public static HttpServletRequest getHttpServletRequest() {
		return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
	}
	
}
 

